package com.tanhua.server.controller;


import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 查询分页推荐好友列表
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto) {
        //调用service查询
        PageResult pr = tanhuaService.recommendation(dto);
        //构造返回结果
        return ResponseEntity.ok(pr);
    }

    /**
     * 今日佳人
     *
     * @return
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 佳人信息
     *
     * @param userId
     * @return
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId) {
        TodayBest vo = tanhuaService.personalInfo(userId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 查看陌生人问题
     *
     * @param userId
     * @return
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {
        String questions = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(questions);
    }

    /**
     * 回复陌生人问题
     *
     * @return
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity stranger(@RequestBody Map map) {
        //前端传过来的userId是Integer类型的
        String skr = map.get("userId").toString();
        Long userId = Long.valueOf(skr);
        String reply = map.get("reply").toString();
        tanhuaService.stranger(userId, reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 左滑右滑
     *
     * @return
     */
    @GetMapping("/cards")
    public ResponseEntity cards() {
        List<TodayBest> list = tanhuaService.cards();
        return ResponseEntity.ok(list);
    }

    /**
     * 喜欢
     *
     * @param likeUserId
     * @return
     */
    @GetMapping("/{id}/love")
    public ResponseEntity likeUser(@PathVariable("id") Long likeUserId) {
        tanhuaService.likeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 不喜欢
     *
     * @param likeUserId
     * @return
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlikeUser(@PathVariable("id") Long likeUserId) {
        tanhuaService.unlikeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 搜附近
     * @param gender  性别
     * @param distance  距离
     * @return
     */
    @GetMapping("/search")
    public ResponseEntity search(String gender,
                                 //设置默认距离为2公里
                                 @RequestParam(defaultValue = "2000")String distance) {
       List<NearUserVo> list = tanhuaService.search(gender, distance);
        return ResponseEntity.ok(list);
    }
}
